package edu.hawaii.myisern.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;

/**
 * Tests the MyOrganization record class.
 * 
 * @author Randy Cox
 * 
 */
public class TestMyOrganization {

  /**
   * Test constructor, make sure fields are initialized.
   */
  @Test
  public void testMyOrganization() {
    MyOrganization organization = new MyOrganization();

    // Check init.
    assertNotNull("Check non-null ID.", organization.getId());
    assertNotNull("Check non-null name.", organization.getName());
    assertNotNull("Check non-null type.", organization.getType());
    assertNotNull("Check non-null contact.", organization.getContact());
    assertNotNull("Check non-null researchers.", organization.getAffiliatedResearchers());
    assertNotNull("Check non-null country.", organization.getCountry());
    assertNotNull("Check non-null keywords.", organization.getResearchKeywords());
    assertNotNull("Check non-null bio.", organization.getResearchDescription());
    assertNotNull("Check non-null bio.", organization.getHomePage());

    // Set up test strings.
    String id = ("FIRST_LAST");
    String name = "First Last ";
    String type = "Type";
    String contact = "Contact";
    String[] researchers = { "Reasearcher1", "Researcher2", "Researcher3" };
    String country = "Country";
    String[] keywords = { "Keyword1", "Keyword2", "Keyword3" };
    String description = "Description";
    String homePage = "Home Page";
    List<String> researcherList = new ArrayList<String>();
    researcherList.add("ResearchA");
    researcherList.add("ResearchB");
    researcherList.add("ResearchC");
    List<String> keywordList = new ArrayList<String>();
    keywordList.add("KeywordA");
    keywordList.add("KeywordB");
    keywordList.add("KeywordC");

    // Set up record vars.
    organization.setName(name);
    organization.setType(type);
    organization.setContact(contact);
    organization.setAffiliatedResearchers(researcherList);
    organization.addAffiliatedResearcher(researchers[0]);
    organization.addAffiliatedResearcher(researchers[1]);
    organization.addAffiliatedResearcher(researchers[2]);
    organization.setCountry(country);
    organization.setResearchKeywords(keywordList);
    organization.addResearchKeyword(keywords[0]);
    organization.addResearchKeyword(keywords[1]);
    organization.addResearchKeyword(keywords[2]);
    organization.setResearchDescription(description);
    organization.setHomePage(homePage);

    // Check vars.
    assertEquals("Check ID.", id, organization.getId());
    assertEquals("Check name.", name, organization.getName());
    assertEquals("Check type.", type, organization.getType());
    assertEquals("Check contact.", contact, organization.getContact());
    assertEquals("Check resA.", researcherList.get(0), organization.getAffiliatedResearchers().get(
        0));
    assertEquals("Check resB.", researcherList.get(1), organization.getAffiliatedResearchers().get(
        1));
    assertEquals("Check resC.", researcherList.get(2), organization.getAffiliatedResearchers().get(
        2));
    assertEquals("Check res1.", researchers[0], organization.getAffiliatedResearchers().get(3));
    assertEquals("Check res2.", researchers[1], organization.getAffiliatedResearchers().get(4));
    assertEquals("Check res3.", researchers[2], organization.getAffiliatedResearchers().get(5));
    assertEquals("Check country.", country, organization.getCountry());
    assertEquals("Check keywordA.", keywordList.get(0), organization.getResearchKeywords().get(0));
    assertEquals("Check keywordB.", keywordList.get(1), organization.getResearchKeywords().get(1));
    assertEquals("Check keywordC.", keywordList.get(2), organization.getResearchKeywords().get(2));
    assertEquals("Check keyword1.", keywords[0], organization.getResearchKeywords().get(3));
    assertEquals("Check keyword2.", keywords[1], organization.getResearchKeywords().get(4));
    assertEquals("Check keyword3.", keywords[2], organization.getResearchKeywords().get(5));
    assertEquals("Check descripiton.", description, organization.getResearchDescription());
    assertEquals("Check homepage.", homePage, organization.getHomePage());

    // Check toString().
    String comma = ", ";
    String expected = id + comma + name + comma + type + comma + contact + comma + country + comma
        + description + comma + homePage;
    assertEquals("Check toString.", expected, organization.toString());

    // Check validate.
    assertTrue("Check validate.", organization.validate());
    organization.setName("");
    assertFalse("Check bad validate.", organization.validate());
  }

}
